package com.gitee.wsl.doc.prosemirror.history

import com.gitee.wsl.doc.prosemirror.history.bean.HistoryState
import com.gitee.wsl.doc.prosemirror.plugin.Plugin

/** Returns a plugin that enables the undo history for an editor. The
// plugin will track undo and redo stacks, which can be used with the
// [`undo`](#history.undo) and [`redo`](#history.redo) commands.
//
// You can set an `"addToHistory"` [metadata
// property](#state.Transaction.setMeta) of `false` on a transaction
// to prevent it from being rolled back by undo.
*/
class HistoryPlugin(config: HistoryOptions = HistoryOptionsConfig()) : Plugin<HistoryState>(HistoryPluginSpec(config))

interface HistoryOptions {
    // The amount of history events that are collected before the
    // oldest events are discarded. Defaults to 100.
    val depth: Int

    // The delay between changes after which a new group should be
    // started. Defaults to 500 (milliseconds). Note that when changes
    // aren't adjacent, a new group is always started.
    val newGroupDelay: Int
}

internal data class HistoryOptionsConfig(
    override val depth: Int = 100,
    override val newGroupDelay: Int = 500
) : HistoryOptions


fun HistoryOptions(depth: Int = 100,
                   newGroupDelay: Int = 500):HistoryOptions = HistoryOptionsConfig(depth,newGroupDelay)
